source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-075.rds.xz")
summary(model)
SOM of size 10x10 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 1065343 objects.
Mean distance to the closest unit in the map: 0.167.
plot(model, type="changes")
df <- mpr.load_data("datos_dia_2k.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:1065343 Length:1065343 Min. : 1.0 Min. :-196.0
Class :character Class :character 1st Qu.: 91.0 1st Qu.: 144.0
Mode :character Mode :character Median :183.0 Median : 201.0
Mean :182.8 Mean : 201.5
3rd Qu.:274.0 3rd Qu.: 263.0
Max. :366.0 Max. : 469.0
tmin precip nevada prof_nieve
Min. :-252.00 Min. : 0.00 Min. :0 Min. : 0.0000
1st Qu.: 47.00 1st Qu.: 0.00 1st Qu.:0 1st Qu.: 0.0000
Median : 100.00 Median : 0.00 Median :0 Median : 0.0000
Mean : 97.54 Mean : 17.05 Mean :0 Mean : 0.6185
3rd Qu.: 153.00 3rd Qu.: 2.00 3rd Qu.:0 3rd Qu.: 0.0000
Max. : 332.00 Max. :3361.00 Max. :0 Max. :1240.0000
longitud latitud altitud
Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.:39.47 1st Qu.: -4.850 1st Qu.: 47
Median :41.29 Median : -1.411 Median : 287
Mean :40.10 Mean : -2.391 Mean : 486
3rd Qu.:42.22 3rd Qu.: 1.296 3rd Qu.: 691
Max. :43.57 Max. : 4.216 Max. :2535
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13
5837 1898 2347 914 51 597 1174 2458 7359 2123 8484 12594 7751
14 15 16 17 18 19 20 21 22 23 24 25 26
1433 211 760 3859 2860 9196 6361 14370 6363 3532 2636 1610 1474
27 28 29 30 31 32 33 34 35 36 37 38 39
10754 13153 13247 9156 14973 18632 8817 5851 7785 5225 4687 10017 5498
40 41 42 43 44 45 46 47 48 49 50 51 52
9328 14163 15271 10574 12524 10682 6527 5699 14728 10724 16696 14714 16477
53 54 55 56 57 58 59 60 61 62 63 64 65
17842 8833 16763 17443 16799 12374 10523 16757 7997 13117 8982 18640 12487
66 67 68 69 70 71 72 73 74 75 76 77 78
11127 10414 14251 14932 6983 15599 16394 13106 16017 11067 12391 15987 16597
79 80 81 82 83 84 85 86 87 88 89 90 91
10163 4004 18063 18797 18283 12544 12668 17777 16330 11025 13495 12002 20082
92 93 94 95 96 97 98 99 100
15907 17914 12853 14530 19145 17069 11972 12864 10280
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 10*10;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip
[1,] -0.89840637 -0.3100110 -0.3750626 0.06451007
[2,] -0.09815587 0.7976878 0.8060144 -0.32102373
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
precip fecha_cnt tmax tmin
0.9819504 0.9794679 0.9790433 0.9759996
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.0 Min. :-252.00 Min. : 0.00
1st Qu.: 91.0 1st Qu.: 145.0 1st Qu.: 47.00 1st Qu.: 0.00
Median :183.0 Median : 201.0 Median : 100.00 Median : 0.00
Mean :182.7 Mean : 201.7 Mean : 97.58 Mean : 15.35
3rd Qu.:274.0 3rd Qu.: 263.0 3rd Qu.: 153.00 3rd Qu.: 1.00
Max. :366.0 Max. : 469.0 Max. : 332.00 Max. :548.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -4.850
Median :0 Median : 0.0000 Median :41.29 Median : -1.411
Mean :0 Mean : 0.6126 Mean :40.10 Mean : -2.394
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.22 3rd Qu.: 1.296
Max. :0 Max. :1240.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 47.0
Median : 287.0
Mean : 485.5
3rd Qu.: 690.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-84.0 Min. :-133.00 Min. : 453.0
1st Qu.: 88.25 1st Qu.: 89.0 1st Qu.: 42.25 1st Qu.: 572.0
Median :253.00 Median :138.0 Median : 92.00 Median : 652.0
Mean :202.57 Mean :135.2 Mean : 81.52 Mean : 710.4
3rd Qu.:305.00 3rd Qu.:184.0 3rd Qu.: 130.00 3rd Qu.: 791.0
Max. :366.00 Max. :344.0 Max. : 240.00 Max. :1500.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -2.3308
Median :0 Median : 0.000 Median :41.77 Median : 0.8856
Mean :0 Mean : 3.178 Mean :40.96 Mean : -0.8443
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 1.9756
Max. :0 Max. :820.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 261.0
Mean : 667.5
3rd Qu.: 953.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 17.0 Min. :-41.00 Min. :1528 Min. :0
1st Qu.: 86.0 1st Qu.: 81.5 1st Qu.: 47.00 1st Qu.:1576 1st Qu.:0
Median :286.0 Median :126.0 Median : 90.00 Median :1741 Median :0
Mean :219.8 Mean :136.5 Mean : 91.35 Mean :1820 Mean :0
3rd Qu.:306.0 3rd Qu.:194.5 3rd Qu.:146.50 3rd Qu.:2036 3rd Qu.:0
Max. :333.0 Max. :252.0 Max. :192.00 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0 1st Qu.:39.48 1st Qu.: 0.3181 1st Qu.: 69.0
Median :0 Median :40.80 Median : 0.4731 Median : 333.0
Mean :0 Mean :39.48 Mean : -1.2462 Mean : 627.3
3rd Qu.:0 3rd Qu.:41.72 3rd Qu.: 1.6841 3rd Qu.:1055.0
Max. :0 Max. :43.36 Max. : 2.4378 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-196.0 Min. :-252.00 Min. : 0.0 Min. :0
1st Qu.: 91.0 1st Qu.: 145.0 1st Qu.: 47.00 1st Qu.: 0.0 1st Qu.:0
Median :182.0 Median : 202.0 Median : 100.00 Median : 0.0 Median :0
Mean :182.4 Mean : 202.5 Mean : 97.78 Mean : 11.1 Mean :0
3rd Qu.:273.0 3rd Qu.: 264.0 3rd Qu.: 153.00 3rd Qu.: 1.0 3rd Qu.:0
Max. :366.0 Max. : 469.0 Max. : 332.00 Max. :292.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -4.850 1st Qu.: 47.0
Median : 0.0000 Median :41.29 Median : -1.411 Median : 287.0
Mean : 0.5838 Mean :40.09 Mean : -2.401 Mean : 484.2
3rd Qu.: 0.0000 3rd Qu.:42.19 3rd Qu.: 1.296 3rd Qu.: 690.0
Max. :1240.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-84.0 Min. :-133.00 Min. : 453.0
1st Qu.: 88.25 1st Qu.: 89.0 1st Qu.: 42.25 1st Qu.: 572.0
Median :253.00 Median :138.0 Median : 92.00 Median : 652.0
Mean :202.57 Mean :135.2 Mean : 81.52 Mean : 710.4
3rd Qu.:305.00 3rd Qu.:184.0 3rd Qu.: 130.00 3rd Qu.: 791.0
Max. :366.00 Max. :344.0 Max. : 240.00 Max. :1500.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -2.3308
Median :0 Median : 0.000 Median :41.77 Median : 0.8856
Mean :0 Mean : 3.178 Mean :40.96 Mean : -0.8443
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 1.9756
Max. :0 Max. :820.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 261.0
Mean : 667.5
3rd Qu.: 953.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 17.0 Min. :-41.00 Min. :1528 Min. :0
1st Qu.: 86.0 1st Qu.: 81.5 1st Qu.: 47.00 1st Qu.:1576 1st Qu.:0
Median :286.0 Median :126.0 Median : 90.00 Median :1741 Median :0
Mean :219.8 Mean :136.5 Mean : 91.35 Mean :1820 Mean :0
3rd Qu.:306.0 3rd Qu.:194.5 3rd Qu.:146.50 3rd Qu.:2036 3rd Qu.:0
Max. :333.0 Max. :252.0 Max. :192.00 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0 1st Qu.:39.48 1st Qu.: 0.3181 1st Qu.: 69.0
Median :0 Median :40.80 Median : 0.4731 Median : 333.0
Mean :0 Mean :39.48 Mean : -1.2462 Mean : 627.3
3rd Qu.:0 3rd Qu.:41.72 3rd Qu.: 1.6841 3rd Qu.:1055.0
Max. :0 Max. :43.36 Max. : 2.4378 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-124.0 Min. :-200.0 Min. :195.0 Min. :0
1st Qu.: 99.0 1st Qu.: 108.0 1st Qu.: 52.0 1st Qu.:257.0 1st Qu.:0
Median :245.0 Median : 146.0 Median : 89.0 Median :300.0 Median :0
Mean :207.2 Mean : 146.5 Mean : 83.4 Mean :317.5 Mean :0
3rd Qu.:307.0 3rd Qu.: 188.0 3rd Qu.: 124.0 3rd Qu.:368.0 3rd Qu.:0
Max. :366.0 Max. : 372.0 Max. : 254.0 Max. :548.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -5.5975 1st Qu.: 61.0
Median : 0.000 Median :42.05 Median : 0.0714 Median : 264.0
Mean : 2.664 Mean :41.20 Mean : -1.9394 Mean : 583.8
3rd Qu.: 0.000 3rd Qu.:42.56 3rd Qu.: 1.6331 3rd Qu.: 816.0
Max. :1001.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.0 Min. :-252.00 Min. : 0.00
1st Qu.: 63.0 1st Qu.: 125.0 1st Qu.: 26.00 1st Qu.: 0.00
Median :126.0 Median : 167.0 Median : 68.00 Median : 0.00
Mean :160.1 Mean : 164.4 Mean : 65.97 Mean : 15.34
3rd Qu.:287.0 3rd Qu.: 211.0 3rd Qu.: 106.00 3rd Qu.: 5.00
Max. :366.0 Max. : 395.0 Max. : 264.00 Max. :292.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.95 1st Qu.: -4.767
Median :0 Median : 0.0000 Median :41.48 Median : -1.411
Mean :0 Mean : 0.8436 Mean :40.43 Mean : -2.238
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.34 3rd Qu.: 1.331
Max. :0 Max. :1240.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 370.0
Mean : 552.6
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-84.0 Min. :-133.00 Min. : 453.0
1st Qu.: 88.25 1st Qu.: 89.0 1st Qu.: 42.25 1st Qu.: 572.0
Median :253.00 Median :138.0 Median : 92.00 Median : 652.0
Mean :202.57 Mean :135.2 Mean : 81.52 Mean : 710.4
3rd Qu.:305.00 3rd Qu.:184.0 3rd Qu.: 130.00 3rd Qu.: 791.0
Max. :366.00 Max. :344.0 Max. : 240.00 Max. :1500.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -2.3308
Median :0 Median : 0.000 Median :41.77 Median : 0.8856
Mean :0 Mean : 3.178 Mean :40.96 Mean : -0.8443
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 1.9756
Max. :0 Max. :820.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 261.0
Mean : 667.5
3rd Qu.: 953.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 17.0 Min. :-41.00 Min. :1528 Min. :0
1st Qu.: 86.0 1st Qu.: 81.5 1st Qu.: 47.00 1st Qu.:1576 1st Qu.:0
Median :286.0 Median :126.0 Median : 90.00 Median :1741 Median :0
Mean :219.8 Mean :136.5 Mean : 91.35 Mean :1820 Mean :0
3rd Qu.:306.0 3rd Qu.:194.5 3rd Qu.:146.50 3rd Qu.:2036 3rd Qu.:0
Max. :333.0 Max. :252.0 Max. :192.00 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0 1st Qu.:39.48 1st Qu.: 0.3181 1st Qu.: 69.0
Median :0 Median :40.80 Median : 0.4731 Median : 333.0
Mean :0 Mean :39.48 Mean : -1.2462 Mean : 627.3
3rd Qu.:0 3rd Qu.:41.72 3rd Qu.: 1.6841 3rd Qu.:1055.0
Max. :0 Max. :43.36 Max. : 2.4378 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-124.0 Min. :-200.0 Min. :195.0 Min. :0
1st Qu.: 99.0 1st Qu.: 108.0 1st Qu.: 52.0 1st Qu.:257.0 1st Qu.:0
Median :245.0 Median : 146.0 Median : 89.0 Median :300.0 Median :0
Mean :207.2 Mean : 146.5 Mean : 83.4 Mean :317.5 Mean :0
3rd Qu.:307.0 3rd Qu.: 188.0 3rd Qu.: 124.0 3rd Qu.:368.0 3rd Qu.:0
Max. :366.0 Max. : 372.0 Max. : 254.0 Max. :548.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -5.5975 1st Qu.: 61.0
Median : 0.000 Median :42.05 Median : 0.0714 Median : 264.0
Mean : 2.664 Mean :41.20 Mean : -1.9394 Mean : 583.8
3rd Qu.: 0.000 3rd Qu.:42.56 3rd Qu.: 1.6331 3rd Qu.: 816.0
Max. :1001.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 37.0 Min. :152.0 Min. : 40 Min. : 0.000 Min. :0
1st Qu.:198.0 1st Qu.:257.0 1st Qu.:139 1st Qu.: 0.000 1st Qu.:0
Median :231.0 Median :290.0 Median :169 Median : 0.000 Median :0
Mean :232.3 Mean :287.8 Mean :169 Mean : 1.619 Mean :0
3rd Qu.:265.0 3rd Qu.:319.0 3rd Qu.:199 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332 Max. :109.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.: -5.498 1st Qu.: 34.0
Median : 0.00000 Median :40.82 Median : -1.636 Median : 147.0
Mean : 0.00189 Mean :39.33 Mean : -2.764 Mean : 330.9
3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 1.168 3rd Qu.: 582.0
Max. :89.00000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-158.0 Min. :-240.00 Min. : 0.00
1st Qu.:286.0 1st Qu.: 114.0 1st Qu.: 23.00 1st Qu.: 0.00
Median :320.0 Median : 152.0 Median : 60.00 Median : 0.00
Mean :298.3 Mean : 150.8 Mean : 56.67 Mean : 31.01
3rd Qu.:343.0 3rd Qu.: 189.0 3rd Qu.: 91.00 3rd Qu.: 38.00
Max. :366.0 Max. : 395.0 Max. : 264.00 Max. :292.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:40.66 1st Qu.: -4.049
Median :0 Median : 0.0000 Median :41.63 Median : -1.117
Mean :0 Mean : 0.4337 Mean :41.01 Mean : -1.660
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.38 3rd Qu.: 1.401
Max. :0 Max. :1240.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 91.0
Median : 507.0
Mean : 620.9
3rd Qu.: 852.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-84.0 Min. :-133.00 Min. : 453.0
1st Qu.: 88.25 1st Qu.: 89.0 1st Qu.: 42.25 1st Qu.: 572.0
Median :253.00 Median :138.0 Median : 92.00 Median : 652.0
Mean :202.57 Mean :135.2 Mean : 81.52 Mean : 710.4
3rd Qu.:305.00 3rd Qu.:184.0 3rd Qu.: 130.00 3rd Qu.: 791.0
Max. :366.00 Max. :344.0 Max. : 240.00 Max. :1500.0
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -2.3308
Median :0 Median : 0.000 Median :41.77 Median : 0.8856
Mean :0 Mean : 3.178 Mean :40.96 Mean : -0.8443
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.38 3rd Qu.: 1.9756
Max. :0 Max. :820.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 261.0
Mean : 667.5
3rd Qu.: 953.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 17.0 Min. :-41.00 Min. :1528 Min. :0
1st Qu.: 86.0 1st Qu.: 81.5 1st Qu.: 47.00 1st Qu.:1576 1st Qu.:0
Median :286.0 Median :126.0 Median : 90.00 Median :1741 Median :0
Mean :219.8 Mean :136.5 Mean : 91.35 Mean :1820 Mean :0
3rd Qu.:306.0 3rd Qu.:194.5 3rd Qu.:146.50 3rd Qu.:2036 3rd Qu.:0
Max. :333.0 Max. :252.0 Max. :192.00 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0 1st Qu.:39.48 1st Qu.: 0.3181 1st Qu.: 69.0
Median :0 Median :40.80 Median : 0.4731 Median : 333.0
Mean :0 Mean :39.48 Mean : -1.2462 Mean : 627.3
3rd Qu.:0 3rd Qu.:41.72 3rd Qu.: 1.6841 3rd Qu.:1055.0
Max. :0 Max. :43.36 Max. : 2.4378 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-124.0 Min. :-200.0 Min. :195.0 Min. :0
1st Qu.: 99.0 1st Qu.: 108.0 1st Qu.: 52.0 1st Qu.:257.0 1st Qu.:0
Median :245.0 Median : 146.0 Median : 89.0 Median :300.0 Median :0
Mean :207.2 Mean : 146.5 Mean : 83.4 Mean :317.5 Mean :0
3rd Qu.:307.0 3rd Qu.: 188.0 3rd Qu.: 124.0 3rd Qu.:368.0 3rd Qu.:0
Max. :366.0 Max. : 372.0 Max. : 254.0 Max. :548.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -5.5975 1st Qu.: 61.0
Median : 0.000 Median :42.05 Median : 0.0714 Median : 264.0
Mean : 2.664 Mean :41.20 Mean : -1.9394 Mean : 583.8
3rd Qu.: 0.000 3rd Qu.:42.56 3rd Qu.: 1.6331 3rd Qu.: 816.0
Max. :1001.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-196.0 Min. :-252.00 Min. : 0.000
1st Qu.: 43.00 1st Qu.: 132.0 1st Qu.: 28.00 1st Qu.: 0.000
Median : 87.00 Median : 176.0 Median : 73.00 Median : 0.000
Mean : 90.02 Mean : 171.2 Mean : 70.69 Mean : 7.394
3rd Qu.:131.00 3rd Qu.: 220.0 3rd Qu.: 115.00 3rd Qu.: 2.000
Max. :259.00 Max. : 349.0 Max. : 228.00 Max. :218.000
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:39.48 1st Qu.: -5.346
Median :0 Median : 0.000 Median :41.38 Median : -1.650
Mean :0 Mean : 1.051 Mean :40.13 Mean : -2.531
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.29 3rd Qu.: 1.272
Max. :0 Max. :1209.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1
1st Qu.: 47
Median : 333
Mean : 518
3rd Qu.: 775
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 37.0 Min. :152.0 Min. : 40 Min. : 0.000 Min. :0
1st Qu.:198.0 1st Qu.:257.0 1st Qu.:139 1st Qu.: 0.000 1st Qu.:0
Median :231.0 Median :290.0 Median :169 Median : 0.000 Median :0
Mean :232.3 Mean :287.8 Mean :169 Mean : 1.619 Mean :0
3rd Qu.:265.0 3rd Qu.:319.0 3rd Qu.:199 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332 Max. :109.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.: -5.498 1st Qu.: 34.0
Median : 0.00000 Median :40.82 Median : -1.636 Median : 147.0
Mean : 0.00189 Mean :39.33 Mean : -2.764 Mean : 330.9
3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 1.168 3rd Qu.: 582.0
Max. :89.00000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-158.0 Min. :-240.00 Min. : 0.00
1st Qu.:286.0 1st Qu.: 114.0 1st Qu.: 23.00 1st Qu.: 0.00
Median :320.0 Median : 152.0 Median : 60.00 Median : 0.00
Mean :298.3 Mean : 150.8 Mean : 56.67 Mean : 31.01
3rd Qu.:343.0 3rd Qu.: 189.0 3rd Qu.: 91.00 3rd Qu.: 38.00
Max. :366.0 Max. : 395.0 Max. : 264.00 Max. :292.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:40.66 1st Qu.: -4.049
Median :0 Median : 0.0000 Median :41.63 Median : -1.117
Mean :0 Mean : 0.4337 Mean :41.01 Mean : -1.660
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.38 3rd Qu.: 1.401
Max. :0 Max. :1240.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 91.0
Median : 507.0
Mean : 620.9
3rd Qu.: 852.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-84.0 Min. :-133.00 Min. : 453.0 Min. :0
1st Qu.: 88.5 1st Qu.: 89.0 1st Qu.: 41.00 1st Qu.: 567.0 1st Qu.:0
Median :246.0 Median :138.0 Median : 91.00 Median : 636.0 Median :0
Mean :200.5 Mean :135.0 Mean : 80.63 Mean : 666.1 Mean :0
3rd Qu.:304.5 3rd Qu.:183.5 3rd Qu.: 129.00 3rd Qu.: 746.0 3rd Qu.:0
Max. :366.0 Max. :344.0 Max. : 240.00 Max. :1014.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -2.6081 1st Qu.: 59.0
Median : 0.000 Median :41.84 Median : 0.9844 Median : 261.0
Mean : 2.972 Mean :41.05 Mean : -0.8301 Mean : 669.5
3rd Qu.: 0.000 3rd Qu.:42.40 3rd Qu.: 1.9756 3rd Qu.: 953.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 17.0 Min. :-41.00 Min. :1528 Min. :0
1st Qu.: 86.0 1st Qu.: 81.5 1st Qu.: 47.00 1st Qu.:1576 1st Qu.:0
Median :286.0 Median :126.0 Median : 90.00 Median :1741 Median :0
Mean :219.8 Mean :136.5 Mean : 91.35 Mean :1820 Mean :0
3rd Qu.:306.0 3rd Qu.:194.5 3rd Qu.:146.50 3rd Qu.:2036 3rd Qu.:0
Max. :333.0 Max. :252.0 Max. :192.00 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0 1st Qu.:39.48 1st Qu.: 0.3181 1st Qu.: 69.0
Median :0 Median :40.80 Median : 0.4731 Median : 333.0
Mean :0 Mean :39.48 Mean : -1.2462 Mean : 627.3
3rd Qu.:0 3rd Qu.:41.72 3rd Qu.: 1.6841 3rd Qu.:1055.0
Max. :0 Max. :43.36 Max. : 2.4378 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-124.0 Min. :-200.0 Min. :195.0 Min. :0
1st Qu.: 99.0 1st Qu.: 108.0 1st Qu.: 52.0 1st Qu.:257.0 1st Qu.:0
Median :245.0 Median : 146.0 Median : 89.0 Median :300.0 Median :0
Mean :207.2 Mean : 146.5 Mean : 83.4 Mean :317.5 Mean :0
3rd Qu.:307.0 3rd Qu.: 188.0 3rd Qu.: 124.0 3rd Qu.:368.0 3rd Qu.:0
Max. :366.0 Max. : 372.0 Max. : 254.0 Max. :548.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -5.5975 1st Qu.: 61.0
Median : 0.000 Median :42.05 Median : 0.0714 Median : 264.0
Mean : 2.664 Mean :41.20 Mean : -1.9394 Mean : 583.8
3rd Qu.: 0.000 3rd Qu.:42.56 3rd Qu.: 1.6331 3rd Qu.: 816.0
Max. :1001.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 19.00 1st Qu.: 44.00 1st Qu.: -38.00 1st Qu.: 0.00
Median : 39.00 Median : 77.00 Median : -12.00 Median : 0.00
Mean : 46.21 Mean : 69.01 Mean : -19.73 Mean : 15.18
3rd Qu.: 66.00 3rd Qu.: 104.00 3rd Qu.: 5.00 3rd Qu.: 12.00
Max. :198.00 Max. : 182.00 Max. : 62.00 Max. :218.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.95 1st Qu.: -3.723
Median :0 Median : 0.000 Median :41.98 Median : 0.595
Mean :0 Mean : 5.931 Mean :41.50 Mean : -1.160
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.433
Max. :0 Max. :1199.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1
1st Qu.: 534
Median : 873
Mean :1092
3rd Qu.:1894
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 19.0 Min. :-28.0 Min. :-70.00 Min. :1013 Min. :0
1st Qu.: 89.0 1st Qu.: 88.0 1st Qu.: 49.00 1st Qu.:1078 1st Qu.:0
Median :284.0 Median :144.0 Median :104.00 Median :1153 Median :0
Mean :224.8 Mean :138.3 Mean : 91.03 Mean :1187 Mean :0
3rd Qu.:308.5 3rd Qu.:188.0 3rd Qu.:135.50 3rd Qu.:1294 3rd Qu.:0
Max. :361.0 Max. :282.0 Max. :213.00 Max. :1500 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.05 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.95 1st Qu.: -1.1993 1st Qu.: 35.0
Median : 0.000 Median :41.17 Median : 0.8031 Median : 251.0
Mean : 5.393 Mean :40.07 Mean : -0.9964 Mean : 646.4
3rd Qu.: 0.000 3rd Qu.:42.19 3rd Qu.: 2.3642 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.1817 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. : 38.0 Min. :-100.00 Min. : 0.000
1st Qu.: 55.00 1st Qu.:155.0 1st Qu.: 52.00 1st Qu.: 0.000
Median : 98.00 Median :190.0 Median : 86.00 Median : 0.000
Mean : 98.53 Mean :191.1 Mean : 88.24 Mean : 5.882
3rd Qu.:138.00 3rd Qu.:228.0 3rd Qu.: 124.00 3rd Qu.: 1.000
Max. :259.00 Max. :349.0 Max. : 228.00 Max. :99.000
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.616
Median :0 Median : 0.0000 Median :41.17 Median : -1.863
Mean :0 Mean : 0.1037 Mean :39.86 Mean : -2.798
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.22 3rd Qu.: 1.179
Max. :0 Max. :1209.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 35.0
Median : 185.0
Mean : 406.6
3rd Qu.: 632.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 37.0 Min. :152.0 Min. : 40 Min. : 0.000 Min. :0
1st Qu.:198.0 1st Qu.:257.0 1st Qu.:139 1st Qu.: 0.000 1st Qu.:0
Median :231.0 Median :290.0 Median :169 Median : 0.000 Median :0
Mean :232.3 Mean :287.8 Mean :169 Mean : 1.619 Mean :0
3rd Qu.:265.0 3rd Qu.:319.0 3rd Qu.:199 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332 Max. :109.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.: -5.498 1st Qu.: 34.0
Median : 0.00000 Median :40.82 Median : -1.636 Median : 147.0
Mean : 0.00189 Mean :39.33 Mean : -2.764 Mean : 330.9
3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 1.168 3rd Qu.: 582.0
Max. :89.00000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :194.0 Min. :-158.0 Min. :-240.00 Min. : 0.000
1st Qu.:304.0 1st Qu.: 110.0 1st Qu.: 14.00 1st Qu.: 0.000
Median :328.0 Median : 149.0 Median : 50.00 Median : 0.000
Mean :322.8 Mean : 144.8 Mean : 44.22 Mean : 3.301
3rd Qu.:347.0 3rd Qu.: 182.0 3rd Qu.: 80.00 3rd Qu.: 0.000
Max. :366.0 Max. : 329.0 Max. : 156.00 Max. :153.000
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.05 Min. :-17.7550
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -3.8314
Median :0 Median : 0.000 Median :41.60 Median : 0.3056
Mean :0 Mean : 0.426 Mean :40.97 Mean : -1.4384
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.33 3rd Qu.: 1.4328
Max. :0 Max. :1240.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 112.0
Median : 534.0
Mean : 658.3
3rd Qu.: 890.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-104.0 Min. :-157.00 Min. : 33 Min. :0
1st Qu.:129.0 1st Qu.: 125.0 1st Qu.: 62.00 1st Qu.: 79 1st Qu.:0
Median :250.0 Median : 166.0 Median : 98.00 Median :114 Median :0
Mean :219.4 Mean : 170.2 Mean : 96.67 Mean :120 Mean :0
3rd Qu.:308.0 3rd Qu.: 215.0 3rd Qu.: 135.00 3rd Qu.:155 3rd Qu.:0
Max. :366.0 Max. : 395.0 Max. : 264.00 Max. :292 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.70 1st Qu.: -5.616 1st Qu.: 69.0
Median : 0.0000 Median :41.83 Median : -2.039 Median : 336.0
Mean : 0.4585 Mean :41.14 Mean : -2.374 Mean : 500.5
3rd Qu.: 0.0000 3rd Qu.:42.59 3rd Qu.: 1.272 3rd Qu.: 691.0
Max. :1001.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-84.0 Min. :-133.00 Min. : 453.0 Min. :0
1st Qu.: 88.5 1st Qu.: 89.0 1st Qu.: 41.00 1st Qu.: 567.0 1st Qu.:0
Median :246.0 Median :138.0 Median : 91.00 Median : 636.0 Median :0
Mean :200.5 Mean :135.0 Mean : 80.63 Mean : 666.1 Mean :0
3rd Qu.:304.5 3rd Qu.:183.5 3rd Qu.: 129.00 3rd Qu.: 746.0 3rd Qu.:0
Max. :366.0 Max. :344.0 Max. : 240.00 Max. :1014.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -2.6081 1st Qu.: 59.0
Median : 0.000 Median :41.84 Median : 0.9844 Median : 261.0
Mean : 2.972 Mean :41.05 Mean : -0.8301 Mean : 669.5
3rd Qu.: 0.000 3rd Qu.:42.40 3rd Qu.: 1.9756 3rd Qu.: 953.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 21.0 Min. : 17.0 Min. :-41.00 Min. :1528 Min. :0
1st Qu.: 86.0 1st Qu.: 81.5 1st Qu.: 47.00 1st Qu.:1576 1st Qu.:0
Median :286.0 Median :126.0 Median : 90.00 Median :1741 Median :0
Mean :219.8 Mean :136.5 Mean : 91.35 Mean :1820 Mean :0
3rd Qu.:306.0 3rd Qu.:194.5 3rd Qu.:146.50 3rd Qu.:2036 3rd Qu.:0
Max. :333.0 Max. :252.0 Max. :192.00 Max. :3361 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0 1st Qu.:39.48 1st Qu.: 0.3181 1st Qu.: 69.0
Median :0 Median :40.80 Median : 0.4731 Median : 333.0
Mean :0 Mean :39.48 Mean : -1.2462 Mean : 627.3
3rd Qu.:0 3rd Qu.:41.72 3rd Qu.: 1.6841 3rd Qu.:1055.0
Max. :0 Max. :43.36 Max. : 2.4378 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-124.0 Min. :-200.0 Min. :195.0 Min. :0
1st Qu.: 99.0 1st Qu.: 108.0 1st Qu.: 52.0 1st Qu.:257.0 1st Qu.:0
Median :245.0 Median : 146.0 Median : 89.0 Median :300.0 Median :0
Mean :207.2 Mean : 146.5 Mean : 83.4 Mean :317.5 Mean :0
3rd Qu.:307.0 3rd Qu.: 188.0 3rd Qu.: 124.0 3rd Qu.:368.0 3rd Qu.:0
Max. :366.0 Max. : 372.0 Max. : 254.0 Max. :548.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -5.5975 1st Qu.: 61.0
Median : 0.000 Median :42.05 Median : 0.0714 Median : 264.0
Mean : 2.664 Mean :41.20 Mean : -1.9394 Mean : 583.8
3rd Qu.: 0.000 3rd Qu.:42.56 3rd Qu.: 1.6331 3rd Qu.: 816.0
Max. :1001.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 19.00 1st Qu.: 44.00 1st Qu.: -38.00 1st Qu.: 0.00
Median : 39.00 Median : 77.00 Median : -12.00 Median : 0.00
Mean : 46.21 Mean : 69.01 Mean : -19.73 Mean : 15.18
3rd Qu.: 66.00 3rd Qu.: 104.00 3rd Qu.: 5.00 3rd Qu.: 12.00
Max. :198.00 Max. : 182.00 Max. : 62.00 Max. :218.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.95 1st Qu.: -3.723
Median :0 Median : 0.000 Median :41.98 Median : 0.595
Mean :0 Mean : 5.931 Mean :41.50 Mean : -1.160
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.433
Max. :0 Max. :1199.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1
1st Qu.: 534
Median : 873
Mean :1092
3rd Qu.:1894
Max. :2535
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 19.0 Min. :-28.0 Min. :-70.00 Min. :1013 Min. :0
1st Qu.: 89.0 1st Qu.: 88.0 1st Qu.: 49.00 1st Qu.:1078 1st Qu.:0
Median :284.0 Median :144.0 Median :104.00 Median :1153 Median :0
Mean :224.8 Mean :138.3 Mean : 91.03 Mean :1187 Mean :0
3rd Qu.:308.5 3rd Qu.:188.0 3rd Qu.:135.50 3rd Qu.:1294 3rd Qu.:0
Max. :361.0 Max. :282.0 Max. :213.00 Max. :1500 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.05 Min. :-17.7550 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.95 1st Qu.: -1.1993 1st Qu.: 35.0
Median : 0.000 Median :41.17 Median : 0.8031 Median : 251.0
Mean : 5.393 Mean :40.07 Mean : -0.9964 Mean : 646.4
3rd Qu.: 0.000 3rd Qu.:42.19 3rd Qu.: 2.3642 3rd Qu.:1055.0
Max. :559.000 Max. :43.57 Max. : 3.1817 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 38 Min. :-100.00 Min. : 0.00 Min. :0
1st Qu.: 33.00 1st Qu.:136 1st Qu.: 33.00 1st Qu.: 0.00 1st Qu.:0
Median : 62.00 Median :157 Median : 58.00 Median : 0.00 Median :0
Mean : 68.09 Mean :157 Mean : 56.16 Mean : 9.16 Mean :0
3rd Qu.: 92.00 3rd Qu.:177 3rd Qu.: 81.00 3rd Qu.: 5.00 3rd Qu.:0
Max. :251.00 Max. :302 Max. : 180.00 Max. :99.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.85 1st Qu.: -4.680 1st Qu.: 58.0
Median : 0.0000 Median :41.38 Median : -1.229 Median : 287.0
Mean : 0.1839 Mean :40.64 Mean : -1.902 Mean : 488.4
3rd Qu.: 0.0000 3rd Qu.:42.27 3rd Qu.: 1.363 3rd Qu.: 687.0
Max. :1080.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 37.0 Min. :152.0 Min. : 40 Min. : 0.000 Min. :0
1st Qu.:198.0 1st Qu.:257.0 1st Qu.:139 1st Qu.: 0.000 1st Qu.:0
Median :231.0 Median :290.0 Median :169 Median : 0.000 Median :0
Mean :232.3 Mean :287.8 Mean :169 Mean : 1.619 Mean :0
3rd Qu.:265.0 3rd Qu.:319.0 3rd Qu.:199 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. :332 Max. :109.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.: -5.498 1st Qu.: 34.0
Median : 0.00000 Median :40.82 Median : -1.636 Median : 147.0
Mean : 0.00189 Mean :39.33 Mean : -2.764 Mean : 330.9
3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 1.168 3rd Qu.: 582.0
Max. :89.00000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :123.0 Min. : -6.0 Min. : 0.000 Min. :0
1st Qu.:107.0 1st Qu.:206.0 1st Qu.: 96.0 1st Qu.: 0.000 1st Qu.:0
Median :132.0 Median :228.0 Median :124.0 Median : 0.000 Median :0
Mean :131.7 Mean :228.2 Mean :123.2 Mean : 2.313 Mean :0
3rd Qu.:157.0 3rd Qu.:250.0 3rd Qu.:154.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :259.0 Max. :349.0 Max. :228.0 Max. :93.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:37.78 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.0000 Median :40.96 Median : -2.4831 Median : 98.0
Mean : 0.0165 Mean :39.02 Mean : -3.7731 Mean : 317.4
3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.8856 3rd Qu.: 541.0
Max. :1209.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)